
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Clocks &#8212; Freedom Metal v201905 documentation</title>
    <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="CPU" href="cpu.html" />
    <link rel="prev" title="Caches" href="cache.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <div class="section" id="clocks">
<h1>Clocks<a class="headerlink" href="#clocks" title="Permalink to this headline">¶</a></h1>
<p>API for manipulating clock sources. </p>
<p>The clock interface allows for controlling the rate of various clocks in the system. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Typedefs</p>
<dl class="type">
<dt id="_CPPv336metal_clock_pre_rate_change_callback">
<span id="_CPPv236metal_clock_pre_rate_change_callback"></span><span id="metal_clock_pre_rate_change_callback"></span><span class="target" id="clock_8h_1a62fbd58edad21e8a5ae178d52cd628f5"></span><em class="property">typedef </em>void (*<code class="descname">metal_clock_pre_rate_change_callback</code>)<span class="sig-paren">(</span>void *priv<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv336metal_clock_pre_rate_change_callback" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Function signature of clock pre-rate change callbacks. </p>
</dd></dl>

<dl class="type">
<dt id="_CPPv337metal_clock_post_rate_change_callback">
<span id="_CPPv237metal_clock_post_rate_change_callback"></span><span id="metal_clock_post_rate_change_callback"></span><span class="target" id="clock_8h_1a4d1fac9337690accb874463be0f170fd"></span><em class="property">typedef </em>void (*<code class="descname">metal_clock_post_rate_change_callback</code>)<span class="sig-paren">(</span>void *priv<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv337metal_clock_post_rate_change_callback" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Function signature of clock post-rate change callbacks. </p>
</dd></dl>

</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="_CPPv323metal_clock_get_rate_hzPK11metal_clock">
<span id="_CPPv223metal_clock_get_rate_hzPK11metal_clock"></span><span id="metal_clock_get_rate_hz__metal_clockCP"></span><span class="target" id="clock_8h_1ae5d567666747aa51cc910879e04bcc8a"></span>long <code class="descname">metal_clock_get_rate_hz</code><span class="sig-paren">(</span><em class="property">const</em> <em class="property">struct</em> <a class="reference internal" href="#_CPPv311metal_clock" title="metal_clock">metal_clock</a> *<em>clk</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv323metal_clock_get_rate_hzPK11metal_clock" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Returns the current rate of the given clock. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>The current rate of the clock in Hz </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal notranslate"><span class="pre">clk</span></code>: The handle for the clock </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv323metal_clock_set_rate_hzP11metal_clockl">
<span id="_CPPv223metal_clock_set_rate_hzP11metal_clockl"></span><span id="metal_clock_set_rate_hz__metal_clockP.l"></span><span class="target" id="clock_8h_1a3670a40780226f31c9dd8ea189e7b4d4"></span>long <code class="descname">metal_clock_set_rate_hz</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv311metal_clock" title="metal_clock">metal_clock</a> *<em>clk</em>, long <em>hz</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv323metal_clock_set_rate_hzP11metal_clockl" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Set the current rate of a clock. </p>
<p><p>Attempts to set the current rate of the given clock to as close as possible to the given rate in Hz. Returns the actual value that’s been selected, which could be anything!</p>
<dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>The new rate of the clock in Hz.</dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal notranslate"><span class="pre">clk</span></code>: The handle for the clock </li>
<li><code class="docutils literal notranslate"><span class="pre">hz</span></code>: The desired rate in Hz </li>
</ul>
</dd>
</dl>
</p>
<p>Prior to and after the rate change of the clock, this will call the registered pre- and post-rate change callbacks. </p>
</dd></dl>

<dl class="function">
<dt id="_CPPv345metal_clock_register_pre_rate_change_callbackP11metal_clock36metal_clock_pre_rate_change_callbackPv">
<span id="_CPPv245metal_clock_register_pre_rate_change_callbackP11metal_clock36metal_clock_pre_rate_change_callbackPv"></span><span id="metal_clock_register_pre_rate_change_callback__metal_clockP.metal_clock_pre_rate_change_callback.voidP"></span><span class="target" id="clock_8h_1ac1401db96e6b29a7e1ecafbefa3fe0b8"></span>void <code class="descname">metal_clock_register_pre_rate_change_callback</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv311metal_clock" title="metal_clock">metal_clock</a> *<em>clk</em>, <a class="reference internal" href="#_CPPv336metal_clock_pre_rate_change_callback" title="metal_clock_pre_rate_change_callback">metal_clock_pre_rate_change_callback</a> <em>cb</em>, void *<em>priv</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv345metal_clock_register_pre_rate_change_callbackP11metal_clock36metal_clock_pre_rate_change_callbackPv" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Register a callback that must be called before a rate change. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal notranslate"><span class="pre">clk</span></code>: The handle for the clock </li>
<li><code class="docutils literal notranslate"><span class="pre">cb</span></code>: The callback to be registered </li>
<li><code class="docutils literal notranslate"><span class="pre">priv</span></code>: Private data for the callback handler </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv346metal_clock_register_post_rate_change_callbackP11metal_clock37metal_clock_post_rate_change_callbackPv">
<span id="_CPPv246metal_clock_register_post_rate_change_callbackP11metal_clock37metal_clock_post_rate_change_callbackPv"></span><span id="metal_clock_register_post_rate_change_callback__metal_clockP.metal_clock_post_rate_change_callback.voidP"></span><span class="target" id="clock_8h_1a51f8c1c9dc234cbcbac4045d5da66642"></span>void <code class="descname">metal_clock_register_post_rate_change_callback</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv311metal_clock" title="metal_clock">metal_clock</a> *<em>clk</em>, <a class="reference internal" href="#_CPPv337metal_clock_post_rate_change_callback" title="metal_clock_post_rate_change_callback">metal_clock_post_rate_change_callback</a> <em>cb</em>, void *<em>priv</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv346metal_clock_register_post_rate_change_callbackP11metal_clock37metal_clock_post_rate_change_callbackPv" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Registers a callback that must be called after a rate change. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal notranslate"><span class="pre">clk</span></code>: The handle for the clock </li>
<li><code class="docutils literal notranslate"><span class="pre">cb</span></code>: The callback to be registered </li>
<li><code class="docutils literal notranslate"><span class="pre">priv</span></code>: Private data for the callback handler </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

</div>
<dl class="class">
<dt id="_CPPv311metal_clock">
<span id="_CPPv211metal_clock"></span><span id="metal_clock"></span><span class="target" id="structmetal__clock"></span><em class="property">struct </em><code class="descname">metal_clock</code><a class="headerlink" href="#_CPPv311metal_clock" title="Permalink to this definition">¶</a><br /></dt>
<dd><em>#include &lt;clock.h&gt;</em><p>The handle for a clock. </p>
<p>Clocks are defined as a pointer to a <code class="docutils literal notranslate"><span class="pre">struct</span> <a class="reference internal" href="#structmetal__clock"><span class="std std-ref"><span class="pre">metal_clock</span></span></a></code>, the contents of which are implementation defined. Users of the clock interface must call functions which accept a <code class="docutils literal notranslate"><span class="pre">struct</span> <a class="reference internal" href="#structmetal__clock"><span class="std std-ref"><span class="pre">metal_clock</span></span></a> <span class="pre">*</span></code> as an argument to interract with the clock.</p>
<p>Note that no mechanism for obtaining a pointer to a <code class="docutils literal notranslate"><span class="pre">struct</span> <a class="reference internal" href="#structmetal__clock"><span class="std std-ref"><span class="pre">metal_clock</span></span></a></code> has been defined, making it impossible to call any of these functions without invoking implementation-defined behavior. </p>
</dd></dl>

</div>


          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../index.html">Freedom Metal</a></h1>








<h3>Navigation</h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction to Freedom Metal</a></li>
<li class="toctree-l1"><a class="reference internal" href="../devguide.html">Developer Guide</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="button.html">Buttons</a></li>
<li class="toctree-l2"><a class="reference internal" href="cache.html">Caches</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Clocks</a></li>
<li class="toctree-l2"><a class="reference internal" href="cpu.html">CPU</a></li>
<li class="toctree-l2"><a class="reference internal" href="gpio.html">GPIO</a></li>
<li class="toctree-l2"><a class="reference internal" href="interrupt.html">Interrupts</a></li>
<li class="toctree-l2"><a class="reference internal" href="itim.html">ITIM</a></li>
<li class="toctree-l2"><a class="reference internal" href="led.html">LEDs</a></li>
<li class="toctree-l2"><a class="reference internal" href="lock.html">Locks</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html">Memory Enumeration</a></li>
<li class="toctree-l2"><a class="reference internal" href="pmp.html">PMPs</a></li>
<li class="toctree-l2"><a class="reference internal" href="shutdown.html">Shutdown</a></li>
<li class="toctree-l2"><a class="reference internal" href="spi.html">SPIs</a></li>
<li class="toctree-l2"><a class="reference internal" href="switch.html">Switches</a></li>
<li class="toctree-l2"><a class="reference internal" href="timer.html">Timer API</a></li>
<li class="toctree-l2"><a class="reference internal" href="tty.html">TTY</a></li>
<li class="toctree-l2"><a class="reference internal" href="uart.html">UARTs</a></li>
</ul>
</li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../index.html">Documentation overview</a><ul>
  <li><a href="../api.html">API Reference</a><ul>
      <li>Previous: <a href="cache.html" title="previous chapter">Caches</a></li>
      <li>Next: <a href="cpu.html" title="next chapter">CPU</a></li>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2019, SiFive Inc..
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.5</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.11</a>
      
      |
      <a href="../_sources/apiref/clock.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>